**************************************
*** MAIN RESULTS: SOCIAL DIVISIONS ***
**************************************

*NOTE: This do-file should be executed on the dataset: "individual-level-data"
*NOTE: To reproduce the main results, please use Stata 15 with the following packages installed:
ssc install blidschemes
ssc install grc1leg
ssc install estout
ssc install coefplot
*NOTE: If packages are already installed, run the do-file from here

xtset year

*** Table 1 ***
*Multilevel logit models predicting Labour vote
estimates clear
eststo: xtlogit votelab i.class4w##c.ilworkerpos i.sex age if bsabes==1, re
eststo: xtlogit votelab i.class4w##c.ilbusinesspos i.sex age if bsabes==1, re
eststo: xtlogit votelab i.class4w##c.ilworkerpos i.class4w##c.ilecon i.class4w##c.ipolarecon i.sex age if bsabes==1, re
eststo: xtlogit votelab i.class4w##c.ilbusinesspos i.class4w##c.ilecon i.class4w##c.ipolarecon i.sex age if bsabes==1, re
esttab

*** Figure 2 ***
*Class voting across worker and busisness emphasis controling for policy effects 
*worker emphasis
xtlogit votelab i.class4##c.ilworkerpos i.class4##c.ilecon i.class4##c.ipolarecon i.sex age if bsabes==1, re
margins, dydx(i(4).class4) at(ilworkerpos=(0(1)9))
marginsplot, scheme(plotplainblind) ylabel(.30 (.05) .55) xlabel(0(1)9) xtitle("Worker emphasis (%)") ///
	 title("") ytitle("Marginal class effect") recast(line) recastci(rarea) ciopts(color(gs14)) ///
	 legend(off) name(MEworker, replace)  
*business emphasis
xtlogit votelab i.class4##c.ilbusinesspos i.class4##c.ilecon i.class4##c.ipolarecon i.sex age if bsabes==1, re
margins, dydx(i(4).class4) at(ilbusinesspos=(0(1)7))
marginsplot, scheme(plotplainblind) ylabel(.30 (.05) .55) xlabel(0(1)7) xtitle("Business emphasis (%)") ///
	 title("") ytitle("Marginal class effect") recast(line) recastci(rarea) ciopts(color(gs14)) ///
	 legend(off) name(MEbusiness, replace)
*plot	 
grc1leg MEworker MEbusiness, rows(1) ///
	 title("") subtitle("") name(fig1, replace)

*** Figure 2 ***
*Plot of standardized interaction effects ***
mat model=J(4,3,.)

xtreg votelab i.class2##c.stdworkerpos i.class2##c.stdecon i.class2##c.stdpolarecon i.sex age if bsabes==1, re	
mat output=r(table)'
mat model[1,1]=output[5,1]
mat model[1,2]=output[5,5]
mat model[1,3]=output[5,6]

xtreg votelab i.class2##c.stdbusinesspos i.class2##c.stdecon i.class2##c.stdpolarecon i.sex age if bsabes==1, re	
mat output=r(table)'
mat model[2,1]=output[5,1]
mat model[2,2]=output[5,5]
mat model[2,3]=output[5,6]

xtreg votelab i.class2##c.stdecon i.class2##c.stdworkerpos i.class2##c.stdbusinesspos i.sex age if bsabes==1, re
mat output=r(table)'
mat model[3,1]=output[5,1]
mat model[3,2]=output[5,5]
mat model[3,3]=output[5,6]

xtreg votelab i.class2##c.stdpolarecon i.class2##c.stdworkerpos i.class2##c.stdbusinesspos i.sex age if bsabes==1, re	
mat output=r(table)'
mat model[4,1]=output[5,1]
mat model[4,2]=output[5,5]
mat model[4,3]=output[5,6]

mat list model
matrix rownames model = 1 2 3 4 

coefplot (matrix(model [.,1]), ci((model [.,2] model [.,3]))), byopts(xrescale) ///
coeflabels(1 = `""Worker emphasis" "({&Delta} st.d.)""' 2 = `""Business emphasis" "({&Delta} st.d.)""' 3 = `""Economic position" "({&Delta} st.d.)""' 4 = `""Economic difference" "({&Delta} st.d.)""', labgap(4) labsize(medsmall)) ///
xline(0, lwidth(medium) lpattern(line) lcolor(black)) grid(none)  xlabel(-0.05(0.01)0.05) ///
citop ciopts(recast(rcap)) levels(95) msymbol(O) xtitle("Change to the 'class gap'") name(fig2, replace)

*END OF DO-FILE
